<?php
/*
 * APP版本管理
 */
if($_POST['act']=='save'){//保存
    if($_POST['editid'] && $_POST['editid']>0){
        $sql = "update ".APPVERSION." set version='".$_POST['version']."',client_system='".$_POST['client_system']."',download_url='".$_POST['download_url']."',description='".$_POST['description']."'";
        if($_POST['update_rule_in']!=''){
            $sql .=",must_updated_rule='".$_POST['update_rule_in']."'";
        }elseif($_POST['update_rule_se']!=''){
            $sql .=",must_updated_rule='nowVersion<".$_POST['update_rule_se']."'";
        }
        $sql .= " where id=".$_POST['editid'];
    }else{
        $update_rule = "";
        if($_POST['update_rule_in']!=''){
            $update_rule = $_POST['update_rule_in'];
        }elseif($_POST['update_rule_se']!=''){
            $update_rule ="nowVersion<".$_POST['update_rule_se'];
        }
        $create_time = date('Y-m-d H:i:s',time());
        $values = "'$_POST[version]','$_POST[client_system]','$_POST[download_url]','$_POST[description]','$update_rule','$create_time'";
        $sql = "insert into ".APPVERSION." (`version`,`client_system`,`download_url`,`description`,`must_updated_rule`,`create_time`) values (".$values.")";
    }
    $db->query($sql);
    msg("?m=global&s=app_version.php");
}
if($_GET['act']=='add' || $_GET['act']=='edit'){//编辑，添加
    if($_GET['act']=='add'){
        $de['version_info'] = array();
    }else{
        $sql = "select * from ".APPVERSION." where id=".$_GET['id'];
        $db->query($sql);
        $de['version_info'] = $db->fetchRow();
    }
    $sql = "select version from ".APPVERSION." where client_system='".$de['version_info']['client_system']."'";
    $de['versions'] = $db->getRows($db->query($sql));
}else{
    $where = "";
    $timeorder = "desc";
    if($_GET['client_system']!=""){
        $where .=" and client_system='$_GET[client_system]'";
    }

    if($_GET['timeorder']=='asc'){
        $timeorder = "asc";
    }
    
    $sql = "select * from ".APPVERSION." where 1".$where." order by create_time ".$timeorder;
    
    include_once("../includes/page_utf_class.php");
    $page = new Page;
    $page->listRows=20;
    $db->query($sql);
    $totalRows = $db->num_rows();
    if (!$page->__get('totalRows')){
        $db->query($sql);
        $page->totalRows = $db->num_rows();
    }
    $sql .= "  limit ".$page->firstRow.",".$page->listRows;
    
    $db->query($sql);
    $totalRows = $db->num_rows();
    if (!$page->__get('totalRows')){
        $db->query($sql);
        $page->totalRows = $db->num_rows();
    }
    $de['page'] = $page->prompt();
    $de['list']=$db->getRows();
    
    $tpl->assign('countpro',$totalRows);
}


$tpl->assign('de',$de);
$tpl->display('app_version.htm');